package org.xxpay.core.common.util;

import java.util.Base64;

import javax.crypto.Cipher;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;

public class MyAesReqEncrypt {

    private static final MyLog logger = MyLog.getLog(MyAesReqEncrypt.class);

    private static String key = "2021jiquanyes324";
    private static String iv = "jiquan2021324yes";

    public static String encrypt(String data) throws Exception {
        try {
            Cipher cipher = Cipher.getInstance("AES/CBC/NoPadding");
            int blockSize = cipher.getBlockSize();

            byte[] dataBytes = data.getBytes();
            int plaintextLength = dataBytes.length;
            if (plaintextLength % blockSize != 0) {
                plaintextLength = plaintextLength + (blockSize - (plaintextLength % blockSize));
            }

            byte[] plaintext = new byte[plaintextLength];
            System.arraycopy(dataBytes, 0, plaintext, 0, dataBytes.length);

            SecretKeySpec keyspec = new SecretKeySpec(key.getBytes(), "AES");
            IvParameterSpec ivspec = new IvParameterSpec(iv.getBytes());

            cipher.init(Cipher.ENCRYPT_MODE, keyspec, ivspec);
            byte[] encrypted = cipher.doFinal(plaintext);

            String str = Base64.getEncoder().encodeToString(encrypted);
            str = str.replaceAll(System.getProperty("line.separator"), "");
            return str;
        } catch (Exception e) {
            logger.error("error", e);
            return null;
        }
    }

    public static String desEncrypt(String data) throws Exception {
        try
        {

            byte[] encrypted1 = Base64.getDecoder().decode(data);
            
            Cipher cipher = Cipher.getInstance("AES/CBC/NoPadding");
            SecretKeySpec keyspec = new SecretKeySpec(key.getBytes(), "AES");
            IvParameterSpec ivspec = new IvParameterSpec(iv.getBytes());
            
            cipher.init(Cipher.DECRYPT_MODE, keyspec, ivspec);
 
            byte[] original = cipher.doFinal(encrypted1);
            String originalString = new String(original);
            return originalString;
        }
        catch (Exception e) {
            logger.error("error", e);
            return null;
        }
    }

    public static void main(String[] args) throws Exception {

        String aa = "WQNk1RYPu3nfYd+uOitvsSKvOQ6/n40lbBoN07ZX+rfxwJzRf2Jk3XcW0ZEpqJAaQ/bCZE/zIfhVPHouhs9HBW2uKnGlnJ6cIXZhRGOK8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